import Vue from 'vue'
const SUCCESS = 1000000
const API_ROOT = server.root + '/newmanage/register/trade'

const awardListResource = Vue.resource(API_ROOT + '/award/list')
const updateAwardResource = Vue.resource(API_ROOT + '/award/update')
export const exportResource = API_ROOT + '/trade/export'
const commissionListResource = Vue.resource(API_ROOT + '/award/free/list')
const updatecommissionResource = Vue.resource(API_ROOT + '/award/free/update')
const saveSwitchResource = Vue.resource(API_ROOT + '/switch/save')
const getSwitchListResource = Vue.resource(API_ROOT + '/switch/list')


export const getAwardList = ({dispatch}, params) => {
  return awardListResource.get(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return Promise.resolve(res.data.data)
      }
      return Promise.reject(res.data)
    })
}
export const updateAward = ({dispatch}, params) => {
  return updateAwardResource.get(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return Promise.resolve(res.data)
      }
      return Promise.reject(res.data)
    })
}
export const getCommissionList = ({dispatch}, params) => {
  return commissionListResource.get(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return Promise.resolve(res.data)
      }
      return Promise.reject(res.data)
    })
}
export const updateCommissionList = ({dispatch}, params) => {
  return updatecommissionResource.get(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return Promise.resolve(res.data)
      }
      return Promise.reject(res.data)
    })
}
export const saveSwitch= ({dispatch}, params) => {
  return saveSwitchResource.get(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return Promise.resolve(res.data)
      }
      return Promise.reject(res.data)
    })
}

export const getSwitchList= ({dispatch}, params) => {
  return getSwitchListResource.save(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return Promise.resolve(res.data)
      }
      return Promise.reject(res.data)
    })
}